package com.iwhalecloud.uncc.dao.impl;

import com.iwhalecloud.uncc.dao.SysConfigDao;
import com.iwhalecloud.uncc.feign.CommonFeignClientService;
import com.iwhalecloud.uncc.model.MqClusterConfig;
import com.iwhalecloud.uncc.model.RedisConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

@Slf4j
@Repository("sysConfigDao")
@ConditionalOnProperty(name = "loadFromDb", havingValue = "false")
public class SysConfigFeignDaoImpl implements SysConfigDao {

    @Autowired
    private CommonFeignClientService commonFeignClientService;

    @Cacheable(value="pbIsppConfig", key="#code")
    @Override
    public String getSysConfig(String code) {
        return this.commonFeignClientService.getSysConfigSpec(code);
    }

    @Override
    @Cacheable(value = "moduleConfig", key = "#module+'-'+#appName+'-'+#code")
    public String getModuleConfig(String module, String appName, String code) {
        return this.commonFeignClientService.getModuleConfig(module, appName, code);
    }

    @Cacheable(value="redisConfig", key="#clusterCode")
    @Override
    public RedisConfig getRedisConfig(String clusterCode) {
        return this.commonFeignClientService.getRedisConfig(clusterCode);
    }

    @Cacheable(value = "clusterConfig", key="#clusterCode")
    @Override
    public MqClusterConfig getMqClusterConfig(String clusterCode) {
        return this.commonFeignClientService.getMqClusterConfig(clusterCode);
    }

    @Override
    public List<Long> getCtgSeq(String seqName, int batchSize) {
        return this.commonFeignClientService.getCtgSeq(seqName, batchSize);
    }

    @Override
    public Long getLocalSeq(String seqName, int batchSize) {
        return this.commonFeignClientService.getLocalSeq(seqName, batchSize);
    }

    @Override
    public Long getSimpleSeq(String seqName) {
        return this.commonFeignClientService.getSimpleSeq(seqName);
    }

    @Override
    @CacheEvict(value = "pbIsppConfig", allEntries = true)
    public void flushSysConfig() {

    }

    @Override
    @CacheEvict(value = "moduleConfig", allEntries = true)
    public void flushModuleConfig() {

    }

    @Override
    public SqlRowSet readSqlRowSet(String sql, Object[] sps) {
        return  this.commonFeignClientService.readSqlRowSet(sql, sps);
    }
}
